//
//  MineShangJiaController.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/13.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

class MineShangJiaController: UIViewController {
    
    let nameArray:[String] = ["商家入驻","广告合作","其他合作"]
    
    var tableView:UITableView = UITableView.init()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.createUI()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.setNavi()
    }
}
extension MineShangJiaController{
    //MARK:设置导航栏选项
    func setNavi(){
        self.navigationItem.title = "商家合作"
        self.navigationController?.navigationBar.barTintColor = .red
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.black]
        self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "", imagStr: "ic_back", fontSize: 14, target: self, action: #selector(leftBarButtonAction))
    }
    //MARK:LeftBarButtonAction
    func leftBarButtonAction(){
        self.navigationController!.popViewController(animated: true)
}
    func createUI(){
        self.view.backgroundColor = BackGroundColor
        let bgView1:UIView = UIView.init()
        self.view.addSubview(bgView1)
        let phoneTextField:UITextField = UITextField.init()
        bgView1.addSubview(phoneTextField)
        bgView1.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(64)
            make.height.equalTo(50)
        }
        phoneTextField.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.height.equalTo(16)
            make.top.equalTo(17)
        }
        bgView1.backgroundColor = .white
        let bgView2:UIView = UIView.init()
        self.view.addSubview(bgView2)
        let hzLabel:UILabel = UILabel.init()
        bgView2.addSubview(hzLabel)
        bgView2.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(50)
            make.top.equalTo(bgView1.snp.bottom).offset(8)
        }
        phoneTextField.placeholder = "请输入您的联系电话"
        phoneTextField.font = UIFont.systemFont(ofSize: 16)
        hzLabel.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.top.equalTo(17)
            make.right.equalTo(-16)
            make.height.equalTo(16)
        }
        bgView2.backgroundColor = .white
        hzLabel.font = UIFont.systemFont(ofSize: 16)
        hzLabel.text = "合作内容"
        
        for i in 0 ..< nameArray.count{
            let button:UIButton = UIButton.init()
            self.view.addSubview(button)
            button.setTitleColor(.white, for: .selected)
            button.setTitleColor(BaseFontColor, for: .normal)
            button.tag = 1000 + i
            button.setTitle(nameArray[i], for: .normal)
            button.setTitle(nameArray[i], for: .selected)
            let space:CGFloat = CGFloat(16) *  CGFloat(i+1)
            let left_Space:CGFloat = (CGFloat(i)*(k_Wide-64)/3)
            button.addTarget(self, action: #selector(buttonSelectAction(_:)), for: .touchUpInside)
            button.snp.makeConstraints({ (make) in
                make.left.equalTo(space + left_Space)
                make.width.equalTo((k_Wide-64)/3)
                make.top.equalTo(bgView2.snp.bottom).offset(10)
                make.height.equalTo(40)
            })
        }
        let bgview3:UIView = UIView.init()
        self.view.addSubview(bgview3)
        bgview3.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(50)
            make.top.equalTo(bgView2.snp.bottom).offset(50+10)
        }
        let bzLabel:UILabel = UILabel.init()
        bgview3.addSubview(bzLabel)
        bzLabel.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.top.equalTo(17)
            make.width.equalTo(40)
            make.height.equalTo(16)
        }
        let bzTextFiled:UITextField = UITextField.init()
        bgview3.addSubview(bzTextFiled)
        bgview3.backgroundColor = .white
        bzTextFiled.snp.makeConstraints { (make) in
            make.left.equalTo(bzLabel.snp.right).offset(0)
            make.right.equalTo(-16)
            make.height.equalTo(16)
            make.top.equalTo(17)
        }
        bzTextFiled.placeholder = "(选填项)"
        bzLabel.text = "备注"
    }
    func buttonSelectAction(_ button:UIButton){
//        let button:UIButton = self.view.viewWithTag(button.tag) as! UIButton
        button.backgroundColor = .red
        switch button.tag {
        case 1000:
            break
        case 1001:
            break
        default:
            break
        }
    }
}
